package testClasses;

import eventManager.EventPortal;
import gameAppLayer.ExternalData;
import gameAppLayer.RootNodePortal;
import gameAppLayer.StrategyCamera;
import gameAppLayer.stateMachine.GameState;
import gameAppLayer.stateMachine.GameStateMachine;
import gameAppLayer.stateMachine.strategyState.StrategyState;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.jme3.input.InputManager;
import com.jme3.renderer.Camera;
import com.jme3.scene.Node;

import stars.StarControl;
import stars.StarGenerator;
import stars.enums.StarParameters;

/*
 * Sandbox test class to develop a single star system.  Model, views, controller, plus interactivity and modifiers.
 */
public class StarSystemSandbox extends GameState { //implements ActionListener {

	private static final Logger logger = Logger.getLogger(StarSystemSandbox.class.getName());
	
	private Camera cam;
	private ExternalData externalData;
	private StrategyCamera stratCam;
	
	public StarSystemSandbox(
			InputManager inputManager,
			ExternalData externalData,
			Camera cam) {
		super("StarSystemSandbox", inputManager);	
		this.cam = cam;
		this.externalData = externalData;
	}

	@Override
	public void onAnalog(String name, float value, float tpf) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAction(String name, boolean isPressed, float tpf) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean clear(GameStateMachine stateMachine) {
		stateMachine.updateEnabled = false;
		boolean deleteCheck = deleteListeners();
		
		logger.log(Level.INFO, "shutDown() " + this.stateID + " SUCCESS");
		return false;
	}

	@Override
	public boolean initialize(GameStateMachine stateMachine) {
		//Register control map with eventManager first
		EventPortal.addControllerMapReference(masterControlMap);

		
		//Create objects, etc.
		StarParameters starParams = externalData.getStarParameters();
		StarGenerator gen = new StarGenerator(starParams);
		StarControl control = gen.createSingleStar("MSOrange");		
		control.registerEvents();
		masterControlMap.put(control.getKey(), control);		
		
		
		//Init camera and controls
		Node camNode = new Node("StrategyCamera");
		stratCam = new StrategyCamera(this.cam);
        stratCam.setMoveSpeed(10f);
        stratCam.setZoomSpeed(1f);
        stratCam.registerInputs(inputManager);
        stratCam.setSpatial(camNode);        
        RootNodePortal.attachChild(camNode);
		
		//Register listeners
        boolean eventCheck = registerListeners();
        
        //Start updates now that this state is finished building
        stateMachine.updateEnabled = true;
        logger.log(Level.INFO, "startUp() " + this.stateID + " SUCCESS");
		return true;
	}

	@Override
	public void update(float tpf) {
		// TODO Auto-generated method stub
		
	}

		

}
